<?php

namespace Mem;

use MemLib\MemBase;
use MemLib\Pdb;

/**
 * 苹果返回base64位数据
 *
 * @version 1.0
 * @author 张云江
 */
class MemOrder_Receipt_info extends MemBase
{
    public function __construct()
    {
        parent::__construct(Pdb::db_order, "t_order_receipt_info");
    }

    /**
     * 插入数据
     * @param mixed $device_id 设备ID
     * @param mixed $receipt_data base64数据
     */
    public function insertDataWithParam($device_id, $receipt_data)
    {
        $insert_dt = date("Y-m-d H:i:s", time());
        $data = array(
            "device_id" => $device_id,
            "receipt_data" => $receipt_data,
            "insert_dt" => $insert_dt
        );
        $res = $this->addData($data);
        if ($res) {
            \Mlog::info("t_order_receipt_info 插入数据成功" . $device_id);
        }
        return $this->getTmpID();
    }

    /**
     * 根据订单详情
     * @param mixed $device_id
     * @return array
     */
    public function getInfoWithdevice_id($device_id)
    {
        $sql = "SELECT * FROM t_order_receipt_info WHERE device_id='{$device_id}';";
        $data = $this->getData($sql, "getInfoWithdevice_id:{$device_id}");
        return $data ? $data[0] : array();
    }

    /**
     * 更新信息
     * @param $updata
     * @param $wheredata
     * @return bool
     */
    public function updateDataWithParam($updata, $wheredata)
    {
        if (empty($updata) || empty($wheredata)) {
            return false;
        }

        $updata = \MemLib\PublicFunc::convertToHtmlKeyVal($updata);
        $wheredata = \MemLib\PublicFunc::convertToHtmlKeyVal($wheredata);

        $ret = $this->updateData($updata, $wheredata);

        return $ret;
    }
}
